package com.xinan.xs;

import com.jfinal.ext.plugin.tablebind.TableBind;
import com.jfinal.kit.StringKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;

import java.sql.Timestamp;
import java.util.List;
import java.sql.Date;

@TableBind(tableName = "hygl_cz")
public class HyglCz extends Model<HyglCz>{
    public static final HyglCz dao = new HyglCz();

    //columns START
    private String ID = "id";  //
    private String CARD = "card";  //卡号
    private String CZJE = "czje";  //充值金额
    private String CZRQ = "czrq";  //充值日期
    private String CZRY = "czry";  //
    private String CARDID = "cardid";  //

    public void setId(int value) {
        set(ID, value);
    }

	public int getId() {
		return get(ID);
	}
    public void setCard(String value) {
        set(CARD, value);
    }

	public String getCard() {
		return get(CARD);
	}
    public void setCzje(String value) {
        set(CZJE, value);
    }

	public String getCzje() {
		return get(CZJE);
	}
    public void setCzrq(Date value) {
        set(CZRQ, value);
    }

	public Date getCzrq() {
		return get(CZRQ);
	}
    public void setCzry(String value) {
        set(CZRY, value);
    }

	public String getCzry() {
		return get(CZRY);
	}
    public void setCardid(String value) {
        set(CARDID, value);
    }

	public String getCardid() {
		return get(CARDID);
	}
	//columns END

    public List<HyglCz> findAll() {
        return find("select * from hygl_cz");
    }
    /**
     * @param   where
     * @return  Record
     */
    public List<Record> findAlls(String where) {
        String sqlExp = " from hygl_cz";
        if(StringKit.notBlank(where)){
                sqlExp += " where " + where;
        }
                return Db.find( "select * " +sqlExp );

    }

    public Page<HyglCz> page(int pageNumber, int pageSize, String where) {
        String sqlExp = "from hygl_cz b";
        if(StringKit.notBlank(where)){
            sqlExp += " where " + where;
        }
        return paginate(pageNumber, pageSize, "select b.*,(select yhm from hygl  a where a.card=b.card)", sqlExp);
    }
    
    public Page<HyglCz> pagetj(int pageNumber, int pageSize, String where) {
        String sqlExp = "from hygl_cz b";
        if(StringKit.notBlank(where)){
            sqlExp += " where " + where;
        }
        return paginate(pageNumber, pageSize, "select b.*,(select yhm from hygl  a where a.card=b.card) as yhm,(select dh from hygl  a where a.card=b.card) as dh  ", sqlExp);
    }
    /*充值记录，合计*/
    public Page<HyglCz> pageCzTj(int pageNumber,int pageSize,String where){
    	String sqlExp = " from hygl_cz";
    	if(StringKit.notBlank(where)){
    		sqlExp += " where "+where;
    	}
    	return paginate(pageNumber,pageSize,"select count(*) as sums,sum(CAST(czje AS DECIMAL(10,2))) as czje",sqlExp);
    }
}

